import { createRouter, createWebHashHistory } from 'vue-router';
import { useNProgress } from '@/utils/progress';

const { start, done } = useNProgress();
const routes = [{
  name: 'notfound',
  path: '/:pathMatch(.*)',
  text: '访问地址不存在',
  meta: {
    title: '访问地址不存在',
  },
  component: () => import('@/error/404.vue')
}];

const router = createRouter({
  history: createWebHashHistory(import.meta.env.VITE_WEB_PATH || '/'),
  routes
});

router.beforeEach((to, _, next) => {
  start();
  next();
});

router.afterEach(() => {
  done();
});

router.onError(() => {
  done();
});

export default router;
